
def build(bld):
    
    
    
    bld.env.CFLAGS_PAYLOADS = ["-nostartfiles", "-nostdlib", "-fno-builtin", "-Ipayloads/tinypy",
                               "-Ipayloads/tinypy/packages","-fno-asynchronous-unwind-tables", "-fPIC"]

    bld.env.LINKFLAGS_PAYLOADS = ["-T../s2l/bld/"+bld.env.TARGET_ARCH+"/script.ld", 
                              "-Wl,-z,norelro,-z,now,-E,-N,--build-id=none", 
                              "-nostartfiles", "-nostdlib", "-fno-builtin", 
                              "-fno-asynchronous-unwind-tables", "-fPIC"]

    hs = []
    for f in bld.path.ant_glob("packages/*.tpy"):
        bld(features="py2bc2h", source =f , target=f.change_ext('.h'))
        hs.append( f.change_ext('.h') )

    bld(rule='cat ${SRC} > ${TGT}', source=hs, target='packages.h')

    loader = "../../s2l/rtl/generic/loader.c"
    envelopeC = "../../s2l/rtl/generic/envelope.c"
    
    bld(features="c cshlib", source=("tiny.c", loader, envelopeC),
                target='tiny', use='PAYLOADS')
                
    bld(features="so2bin", source = 'libtiny.so', target='tiny')
